package com.ruoyi.comprehensive.controller;

import java.util.List;

import com.ruoyi.comprehensive.domain.PetitionLetterProcess;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.comprehensive.domain.PetitionLetter;
import com.ruoyi.comprehensive.service.IPetitionLetterService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 网上信访Controller
 *
 * @author Allen
 * @date 2021-08-31
 */
@RestController
@RequestMapping("/comprehensive/petitionLetter")
public class PetitionLetterController extends BaseController {
    @Autowired
    private IPetitionLetterService petitionLetterService;

    /**
     * 查询网上信访列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:petitionLetter:list')")
    @GetMapping("/list")
    public TableDataInfo list(PetitionLetter petitionLetter) {
        startPage();
        List<PetitionLetter> list = petitionLetterService.selectPetitionLetterList(petitionLetter);
        return getDataTable(list);
    }


    /**
     * 导出网上信访列表
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:petitionLetter:export')")
    @Log(title = "网上信访列表", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(PetitionLetter petitionLetter) {
        List<PetitionLetter> list = petitionLetterService.selectPetitionLetterList(petitionLetter);
        ExcelUtil<PetitionLetter> util = new ExcelUtil<PetitionLetter>(PetitionLetter.class);
        return util.exportExcel(list, "网上信访数据");
    }

    /**
     * 获取网上信访详细信息
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:petitionLetter:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return AjaxResult.success(petitionLetterService.selectPetitionLetterById(id));
    }

    /**
     * 新增网上信访
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:petitionLetter:add')")
    @Log(title = "网上信访", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody PetitionLetter petitionLetter) {
        return toAjax(petitionLetterService.insertPetitionLetter(petitionLetter));
    }

    /**
     * 修改网上信访
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:petitionLetter:edit')")
    @Log(title = "网上信访", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody PetitionLetter petitionLetter) {
        return toAjax(petitionLetterService.updatePetitionLetter(petitionLetter));
    }

    /**
     * 网上信访完结
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:petitionLetter:end')")
    @Log(title = "网上信访完结", businessType = BusinessType.UPDATE)
    @PostMapping("end")
    public AjaxResult end(@RequestParam("id") Long id) {
        return toAjax(petitionLetterService.endPetitionLetter(id));
    }

    /**
     * 网上信访回复
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:petitionLetter:replay')")
    @Log(title = "网上信访回复", businessType = BusinessType.UPDATE)
    @PostMapping("replay")
    public AjaxResult replay(@RequestBody PetitionLetterProcess petitionLetterProcess) {

        return toAjax(petitionLetterService.replay(petitionLetterProcess));
    }

    /**
     * 删除网上信访
     */
    @PreAuthorize("@ss.hasPermi('comprehensive:petitionLetter:remove')")
    @Log(title = "网上信访", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(petitionLetterService.deletePetitionLetterByIds(ids));
    }
}
